package it.trekker.dao;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

// TODO: incorporare GPSCoordinate in Photo e fare refactoring (vedi Tomboy notes - TrekkerServer: TODO)

@Entity
public class Photo {
	
	protected int id;
	protected String path;
	protected GPSCoordinate location;
	protected Excursion excursion;
	
	public Photo() {
	}
	
	public Photo(String path, Excursion excursion) {
		this.path = path;
		this.excursion = excursion;
	}
	
	public Photo(Photo photo) {
		if(photo != null) {
			this.id = -1;
			this.path = photo.getPath();
			this.location = new GPSCoordinate(photo.getLocation());
		}
	}
	
	@Id
	@GeneratedValue
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Column(unique = true)
	public String getPath() {
		return path;
	}
	
	public void setPath(String path) {
		this.path = path;
	}
	
	public GPSCoordinate getLocation() {
		return location;
	}

	public void setLocation(GPSCoordinate location) {
		this.location = location;
	}

	@ManyToOne(
			fetch=FetchType.LAZY,
			cascade={CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH}
	)
	public Excursion getExcursion() {
		return excursion;
	}

	public void setExcursion(Excursion excursion) {
		this.excursion = excursion;
	}
}
